package com.tjmc.company.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.CompanyBenefitsInfoEntity;
import com.tjmc.company.service.CompanyBenefitsInfoService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 企业福利信息表
 *
 * @author recruit
 * @date 2024-11-14 16:55:50
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/companyBenefitsInfo" )
@Tag(description = "companyBenefitsInfo" , name = "企业福利信息表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CompanyBenefitsInfoController {

    private final CompanyBenefitsInfoService companyBenefitsInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param companyBenefitsInfo 企业福利信息表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getCompanyBenefitsInfoPage(@ParameterObject Page page, @ParameterObject CompanyBenefitsInfoEntity companyBenefitsInfo) {
        LambdaQueryWrapper<CompanyBenefitsInfoEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(companyBenefitsInfoService.page(page, wrapper));
    }

    /**
     * 通过ID查询
     * @param id
     * @return
     */
    @Operation(summary = "通过ID查询" , description = "通过ID查询" )
    @GetMapping("/{id}")
    public R getCompanyBenefitsInfoById(@PathVariable("id") Long id) {
        return R.ok(companyBenefitsInfoService.getById(id));
    }


    /**
     * 通过条件查询企业福利信息表
     * @param companyBenefitsInfo 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject CompanyBenefitsInfoEntity companyBenefitsInfo) {
        return R.ok(companyBenefitsInfoService.list(Wrappers.query(companyBenefitsInfo)));
    }

    /**
     * 新增企业福利信息表
     * @param companyBenefitsInfo 企业福利信息表
     * @return R
     */
    @Operation(summary = "新增企业福利信息表" , description = "新增企业福利信息表" )
    @SysLog("新增企业福利信息表" )
    @PostMapping
    public R save(@RequestBody CompanyBenefitsInfoEntity companyBenefitsInfo) {
        return R.ok(companyBenefitsInfoService.save(companyBenefitsInfo));
    }

    /**
     * 修改企业福利信息表
     * @param companyBenefitsInfo 企业福利信息表
     * @return R
     */
    @Operation(summary = "修改企业福利信息表" , description = "修改企业福利信息表" )
    @SysLog("修改企业福利信息表" )
    @PutMapping
    public R updateById(@RequestBody CompanyBenefitsInfoEntity companyBenefitsInfo) {
        return R.ok(companyBenefitsInfoService.updateById(companyBenefitsInfo));
    }

    /**
     * 通过id删除企业福利信息表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除企业福利信息表" , description = "通过id删除企业福利信息表" )
    @SysLog("通过id删除企业福利信息表" )
    @DeleteMapping
    public R removeById(@RequestBody Integer[] ids) {
        return R.ok(companyBenefitsInfoService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param companyBenefitsInfo 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<CompanyBenefitsInfoEntity> exportExcel(CompanyBenefitsInfoEntity companyBenefitsInfo,Integer[] ids) {
        return companyBenefitsInfoService.list(Wrappers.lambdaQuery(companyBenefitsInfo).in(ArrayUtil.isNotEmpty(ids), CompanyBenefitsInfoEntity::getId, ids));
    }

    /**
     * 导入excel 表
     * @param companyBenefitsInfoList 对象实体列表
     * @param bindingResult 错误信息列表
     * @return ok fail
     */
    @PostMapping("/import")
    public R importExcel(@RequestExcel List<CompanyBenefitsInfoEntity> companyBenefitsInfoList, BindingResult bindingResult) {
        return R.ok(companyBenefitsInfoService.saveBatch(companyBenefitsInfoList));
    }
}
